package com.ithao.controller;

import com.ithao.entity.PageResult;
import com.ithao.entity.QueryPageBean;
import com.ithao.entity.Result;
import com.ithao.pojo.Industry;
import com.ithao.service.IndustryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @description ：企业行业方向控制器
 * @version: 1.0
 */
@Slf4j
@RestController
@RequestMapping("/industry")
public class IndustryController{

	@Autowired
	private IndustryService industryService;

	@RequestMapping("findListAll")
	public Result findListAll (){
		try{
			List<Industry> industryList = industryService.findListAll();
			return new Result(true,"获取成功",industryList);
		}catch(RuntimeException e){
		    log.error("IndustryController findListAll",e);
		    return new Result(false,"获取失败");
		}
	}
	@RequestMapping("/findPage")
	public Result findPage(@RequestBody QueryPageBean queryPageBean){
		if (queryPageBean == null) {
			queryPageBean = new QueryPageBean();
			queryPageBean.setCurrentPage(1);
			queryPageBean.setPageSize(10);
		}
		PageResult pageResult = industryService.findPage(queryPageBean);
		log.info("[分页查找行业方向] pageResult :{}",pageResult);
		return new Result(true,"分页查找方向成功",pageResult);
	}

	@PostMapping("/delete")
	public Result delete(@RequestParam("id") Integer id) {
		log.info("[方向删除] id:{}",id);
		industryService.delete(id);
		return new Result(true,"删除成功");

	}

	@PostMapping("/add")
	public Result add(@RequestBody Industry industry) {
		log.info("[新增方向] industry:{}",industry);
		industryService.add(industry);
		return new Result(true,"新增成功");
	}
}
